﻿using UnityEngine;
// using GoogleMobileAds.Api;
using System;
using UnityEngine.Advertisements;

/**
  * Scene:All
  * Object:WebelinxCMS
  * Description: Scripta za komunikaciju sa native WebelinxCMS-om. Radi i za Android i za iOS. U sebi sadrzi f-je za prikaz Interstial-a, video reklama, za prikaz i sklanjanje banner-a, kao i za uzimanje raznih vrednosti sa servera.
  * Pre upotrebe skripte procitati uputstvo koje se nalazi na putanji Z:\+Unity\Unity Integration Guide for WebelinxCMS\
  **/
public class AdsManager : MonoBehaviour
{
    #region AdMob

    [Header("Admob")] public string adMobAppID = "";
    public string interstitalAdMobId = "ca-app-pub-3940256099942544/1033173712";
    public string videoAdMobId = "ca-app-pub-3940256099942544/5224354917";

    #endregion

    [Space(15)]

    #region

    [Header("UnityAds")]
    public string unityAdsGameId;

    public string unityAdsVideoPlacementId = "rewardedVideo";

    #endregion

    private static AdsManager _instance;

    public static AdsManager Instance
    {
        get
        {
            if (_instance == null) _instance = FindObjectOfType(typeof(AdsManager)) as AdsManager;
            return _instance;
        }
    }

    void Awake()
    {
        DontDestroyOnLoad(gameObject);
        InitializeAds();
    }

    void InitializeAds()
    {
    }

    public void ShowInterstitial()
    {
        ShowAdMob();
    }

    public void IsVideoRewardAvailable()
    {
        if (isVideoAvaiable())
        {
            GameData.bWatchVideoReady = true;
            if (GameData.bWatchVideoStart) ShowVideoReward(1);
        }
        else
        {
            GameData.bWatchVideoReady = false;
            if (GameData.bWatchVideoStart)
                Camera.main.SendMessage("FinishWatchingVideoError", true, SendMessageOptions.DontRequireReceiver);
        }
    }

    public void ShowVideoReward(int ID)
    {
    }

    public void ShowAdMob()
    {
    }

    bool isVideoAvaiable()
    {
#if !UNITY_EDITOR
		// if(Advertisement.IsReady(unityAdsVideoPlacementId))
		// {
		// 	return true;
		// }
		// else if(rewardBasedAdMobVideo.IsLoaded())
		// {
		// 	return true;
		// }
#endif
        return false;
    }
}
